# @Time : 2024/11/10 16:27
# @Author : Fioman 
# @Phone : 13149920693
"""
什么是笛卡尔积式的数据:
就是两个可迭代序列,然后1个序列的值和另外一个序列的分别组合,最后组合成m*n个数的情况.
m和n是两个序列的长度,比如使用列表推导式实现之前的扑克牌
"""
from collections import namedtuple

Card = namedtuple('Card', ['suit', 'rank'])
suits = ["黑桃", "红桃", "方片", "梅花"]
ranks = [str(i) for i in range(2, 11)] + list("JQKA")
poker = [Card(suit, rank) for suit in suits for rank in ranks]
poker.append(Card("大王", ""))
poker.append(Card("小王", ""))
print(poker)

"""
这样生成的数据的顺序是先遍历rank就是黑桃和黑桃一起显示,红桃和红桃一起显示.
如果要生成哪种点数一起显示的话,比如四个花色的2显示在一起,可以先遍历rank,再遍历花色.
"""

poker = [Card(suit, rank) for rank in ranks for suit in suits]
poker.append(Card("大王", ""))
poker.append(Card("小王", ""))
print(poker)
